strana 404
----------
<Grid x:Name="LayoutRoot" Background="White">
  <Grid.RowDefinitions>
    <RowDefinition Height="6*" />
    <RowDefinition Height="1*" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="1*" />
    <ColumnDefinition Width="1*" />
  </Grid.ColumnDefinitions>

  <RichTextBox Name="rtaLevy" Grid.Column="0" Grid.Row="0" 
    Margin="5" TextWrapping="Wrap" />
  <RichTextBox Name="rtaPravy" Grid.Column="1" Grid.Row="0" 
    Margin="5" TextWrapping="Wrap"/>
  <Button x:Name="btCopy"  Content="Kopruj" Grid.Column="0" 
    Grid.Row="1" Click="btCopy_Click" />
  <Button x:Name="btPaste" Content="Vlo" Grid.Column="1" 
    Grid.Row="1" Click="btPaste_Click" />
</Grid>



C#:
string LoremIpsum = "Lorem ipsum dolor sit amet, consectetur adipisicing elit," +
  "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." +
  "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris " +
  "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in " + 
  "reprehenderit in voluptate velit esse cillum dolore eu fugiat " +
  " nulla pariatur.";

public MainPage()
{
  InitializeComponent();
  rtaLevy.Selection.Text = LoremIpsum;
}

private void btCopy_Click(object sender, RoutedEventArgs e)
{
  Clipboard.SetText(rtaLevy.Selection.Text);
}

private void btPaste_Click(object sender, RoutedEventArgs e)
{
  rtaPravy.Selection.Text = Clipboard.GetText();
}



strana 405
----------
C#:
private void btCopy_Click(object sender, RoutedEventArgs e)
{
  if (rtaLevy.Selection.Text.Length > 0)
  {
    Clipboard.SetText(rtaLevy.Selection.Text);
  }
  else
  {
    MessageBox.Show("Nen vybrn text pro koprovn.");
  }
}

private void btPaste_Click(object sender, RoutedEventArgs e)
{
  if (Clipboard.ContainsText())
  {
    aPravy.Selection.Text = Clipboard.GetText();
  }
  else
  {
    MessageBox.Show("Schrnka neobsahuje text pro vloen.");
  }
}



strana 406
----------

<Grid x:Name="LayoutRoot" Background="White">
  <StackPanel>
    <Image  Stretch="Fill" Source="/SLprint;component/mapa1.jpg" />
    <Button Content="T i s k" Click="Button_Click"></Button>
  </StackPanel>
</Grid>


C#:
private void Button_Click(object sender, RoutedEventArgs e)
{
  PrintDocument pd = new PrintDocument();
  pd.PrintPage += (s, args) =>
  {
    args.PageVisual = LayoutRoot;
  };
  pd.Print();
}



strana 407
----------
<Grid x:Name="LayoutRoot" Background="White">
  <Image  Stretch="Fill" Source="/Drag;component/sl.jpg" />
  <Canvas Name="canPodlozka"  Background="Transparent"
    AllowDrop="True" Drop="canPodlozka_Drop" />
</Grid>



C#:
private Image VytvorObrazek(FileInfo droppedFile)
{
  FileStream fileStream = droppedFile.OpenRead();
  {
    BitmapImage bitmapImage = new BitmapImage();
    bitmapImage.SetSource(fileStream);
    Image img = new Image() 
    { 
      Source = bitmapImage, Width = 150, Margin = new Thickness(5.0)
    };

    return img;
  }
}


private void canPodlozka_Drop(object sender, DragEventArgs e)
{
  FileInfo[] droppedFiles = e.Data.GetData(DataFormats.FileDrop) as FileInfo[];

  foreach (FileInfo droppedFile in droppedFiles)
  {
    Border bdRamik = new Border()
    {
      Child = VytvorObrazek(droppedFile),
    };
    canPodlozka.Children.Add(bdRamik);
  }
}


strana 409
----------
C#:
private bool KontrolaTypu(string pripona)
{
  return (pripona.Equals(".jpg", StringComparison.InvariantCultureIgnoreCase)
    || pripona.Equals(".jpeg", StringComparison.InvariantCultureIgnoreCase)
    || pripona.Equals (".png", StringComparison.InvariantCultureIgnoreCase));
}



strana 410
----------
C#:
private SolidColorBrush brVyber = new SolidColorBrush(Colors.Blue);
private SolidColorBrush brNormal = new SolidColorBrush(Colors.Transparent);

private void canPodlozka_Drop(object sender, DragEventArgs e)
{
  FileInfo[] droppedFiles = e.Data.GetData(DataFormats.FileDrop) as FileInfo[];

  foreach (FileInfo droppedFile in droppedFiles)
  {
    if (KontrolaTypu(droppedFile.Extension))
    {

    Point dropPoint = e.GetPosition(canPodlozka);

    Border bdRamecek = new Border()
    {
      Child = VytvorObrazek(droppedFile),
      Background = brNormal,
      Margin = new Thickness(10.0),
      Cursor = Cursors.Hand,
    };

    bdRamik.SetValue(Canvas.LeftProperty, dropPoint.X);
    bdRamik.SetValue(Canvas.TopProperty, dropPoint.Y);

    ToolTipService.SetToolTip(bdRamik, droppedFile.Name);

    bdRamik.MouseEnter += new MouseEventHandler(imagePlaceHolder_MouseEnter);
    bdRamik.MouseLeave += new MouseEventHandler(imagePlaceHolder_MouseLeave);

    canPodlozka.Children.Add(bdRamecek);
    }
  }
}





strana 412
----------

<Grid x:Name="LayoutRoot"  Background="White">
  <Grid.RowDefinitions>
    <RowDefinition Height="1*" />
    <RowDefinition Height="1*" />
    <RowDefinition Height="3*" />
  </Grid.RowDefinitions>

  <TextBlock  x:Name="tbDrop"  AllowDrop="True" Grid.Row="0"  />

  <ListBox x:Name="listBox" Background="LightGray" Margin="10" Grid.Row="1" 
    VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />

  <ScrollViewer VerticalAlignment="Stretch" 
    HorizontalAlignment="Stretch" Grid.Row="2" >
    <StackPanel Grid.Row="1" Grid.Column="0" VerticalAlignment="Stretch" 
      HorizontalAlignment="Stretch">
    <StackPanel x:Name="xamlViewer" MaxWidth="400" />
      <Image x:Name="image" Width="500" Height="300" />
    </StackPanel>
  </ScrollViewer>
</Grid>


C#:

public MainPage()
  {
    InitializeComponent();
    Loaded += new RoutedEventHandler( MainPage_Loaded );
  }

  void MainPage_Loaded( object sender, RoutedEventArgs e )
  {
    tbDrop.Drop += doDrop;
    tbDrop.DragEnter += doDragEnter;
    tbDrop.DragLeave += doDragLeave;
  }

  private static string GetSenderName( object sender )
  {
    FrameworkElement fe = sender as FrameworkElement;
    return fe.Name;
  }

  private void doDragEnter(object sender, DragEventArgs e)
  {
    string senderName = GetSenderName(sender);
    listBox.Items.Add("Vstup: " + senderName);
  }

  private void doDragLeave(object sender, DragEventArgs e)
  {
    string senderName = GetSenderName(sender);
    listBox.Items.Add("Opusteni: " + senderName);
  }

  private void doDrop( object sender, DragEventArgs e )
  {
    string objectName = GetSenderName( sender );
    listBox.Items.Add( "Drop Event: " + objectName );

    if ( e.Data == null )  return;

    IDataObject dataObject = e.Data as IDataObject;
    FileInfo[] files =  dataObject.GetData( DataFormats.FileDrop ) 
      as FileInfo[];

    foreach ( FileInfo file in files )
    {
      listBox.Items.Add("File " + file.Name + " 
        [Size: " + file.Length + "]" );

      // XAML
      if ( file.Extension.Equals( ".xaml" ) )
      {
        string contents;
        Stream stream = file.OpenRead();
        StreamReader reader = new StreamReader(stream);
        contents = reader.ReadToEnd();
        UIElement uiElement = XamlReader.Load( contents ) as UIElement;
        this.xamlViewer.Children.Add( uiElement );
      }

      else if ( file.Extension.Equals( ".mp4" ) )
      {
        var me = new MediaElement();
        me.Width = 400;  
        me.Height = 300;
        me.Source = new Uri( file.Name, UriKind.RelativeOrAbsolute );
        this.xamlViewer.Children.Add( me );
        me.Play();
      }
      else  // jin typ dokumentu
      {
        try  
        {
          using ( var stream = file.OpenRead() )
          {
            var imageSource = new BitmapImage();
            imageSource.SetSource( stream );
            image.Source = imageSource;
          }
        }
        catch ( Exception )
        {
          listBox.Items.Add( "Oops, " + file.Name + " is not an image file" );
        }
      }
    }
  }
}


strana 415
----------
<Grid x:Name="LayoutRoot" Background="White">
  <Grid.RowDefinitions>
    <RowDefinition Height="30" />
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>
  <StackPanel Name="stackPanel1"  Orientation="Horizontal">
    <Button x:Name="btBold" Content="Bold" Height="20" Width="60" 
      Click="btBold_Click" />
    <Button x:Name="btItal" Content="Italics" Height="20" Width="60" 
      Click="btItal_Click" />
    <Button x:Name="btZmena" Content="Zmna" Margin="50,0" 
      Height="20" Width="60" Click="btZmena_Click" />
  </StackPanel>

  <RichTextBox x:Name="rta" Grid.Row="1" TextWrapping="Wrap" 
    IsReadOnly="False">
    <Paragraph x:Name="N1" FontFamily="Arial" FontSize="36" 
      FontWeight="Bold" TextAlignment="Center" 
      
      Lorem Ipsum
      <LineBreak />
    </Paragraph>
    <Paragraph x:Name="P1" FontFamily="Georgia" FontSize="14" 
      TextAlignment="Left">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
      do eiusmod tempor incididunt ut labore et dolore magna aliqua.
      <LineBreak />
      <Italic>
        Ut enim ad minim veniam, quis nostrud exercitation ullamco 
        laboris nisi ut aliquip ex ea commodo consequat.
      </Italic>
      <LineBreak />
      <Bold>
        Duis aute irure dolor in reprehenderit in voluptate velit 
        esse cillum dolore eu fugiat nulla pariatur.
      </Bold>
      <LineBreak />
      <Run x:Name="run1" Text="Excepteur sint occaecat 
        cupidatat non proident," />
    </Paragraph>

  </RichTextBox>
</Grid>


C#:
private void btBold_Click(object sender, RoutedEventArgs e)
{
  if (!string.IsNullOrEmpty(rta.Selection.Text))
  {
    rta.Selection.SetPropertyValue(
    TextElement.FontWeightProperty, FontWeights.Bold);
  }
}

private void btItal_Click(object sender, RoutedEventArgs e)
{
  if (!string.IsNullOrEmpty(rta.Selection.Text))
  {
    rta.Selection.SetPropertyValue(
    TextElement.FontStyleProperty,  FontStyles.Italic);
  }
}

private void btZmena_Click(object sender, RoutedEventArgs e)
{
  run1.Text = "Dynamick zmna asti textu";
  run1.FontSize = 22;
  run1.FontWeight = FontWeights.Bold;
}



strana 417
----------
<Grid x:Name="LayoutRoot" Background="White">
  <StackPanel>
    <StackPanel Orientation="Horizontal" >
      <TextBlock Text="Vysln" FontSize="30" />
      <Button x:Name="btAkce" Height="30" Margin="20" Click="btAkce_Click" />
    </StackPanel>
    <TextBlock x:Name="vystup" />
  </StackPanel>
</Grid>



C#:

using System.Windows.Messaging;

private LocalMessageSender messageSender;
private int nZprava = 1;

public MainPage()
{
  InitializeComponent();
  AktualizaceTlacitka ();
  messageSender = new LocalMessageSender("receiver", LocalMessageSender.Global);
  messageSender.SendCompleted += ms_SendCompleted;
  SendMessage("Zprva z konstruktoru");
}

private void AktualizaceTlacitka()
{
  btAkce.Content = "Vyli zprvu 'slo " + nZprava + "'";
}


private void btAkce_Click(object sender, RoutedEventArgs e)
{
  SendMessage("slo " + nZprava);
  nZprava++;
  AktualizaceTlacitka();
}
private const int MAX_ATTEMPTS = 10000;
private int attempt = 1;

private void SendMessage(string message)
{
  messageSender.SendAsync(message, attempt);
}

private void ms_SendCompleted(object sender, SendCompletedEventArgs e)
{
  if (e.Error != null)
  {
    LogError(e);
    attempt++;
    if (attempt > MAX_ATTEMPTS)
    {
      vystup.Text = "Nen mon vyslat zprvu.";
      return;
    }
    SendMessage(e.Message);
    return;
  }

  vystup.Text =
    "Message: " + e.Message + Environment.NewLine +
    "Attempt " + (int)e.UserState +
    " completed." + Environment.NewLine +
    "Response: " + e.Response + Environment.NewLine +
    "ReceiverName: " + e.ReceiverName + Environment.NewLine +
    "ReceiverDomain: " + e.ReceiverDomain;

    // Reset attempt counter.
    attempt = 1;
}

private void LogError(SendCompletedEventArgs e)
{
  System.Diagnostics.Debug.WriteLine(
    "CHYBA {0}: {1}: {2}", (int)e.UserState,
    e.Error.GetType().ToString(), e.Error.Message);
}



strana 419
----------
<Grid x:Name="LayoutRoot" Background="White">
  <StackPanel >
    <TextBlock Text="Pjem" FontSize="20" />
    <TextBlock x:Name="vystup"/>
  </StackPanel>
</Grid>



C#:
{
  InitializeComponent();

  LocalMessageReceiver messageReceiver =
    new LocalMessageReceiver("receiver",
    ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain);
  messageReceiver.MessageReceived += mr_MessageReceived;

  try
  {
     messageReceiver.Listen();
  }
  catch (ListenFailedException)
  {
    vystup.Text = "Nen mon pijmat zprvy." + Environment.NewLine 
    "Je sputna jin pijmac aplikace s nzvem 'receiver'.";
  }
}

private void mr_MessageReceived(object sender, MessageReceivedEventArgs e)
{
  e.Response = "response to " + e.Message;
  vystup.Text =
    "Message: " + e.Message + Environment.NewLine +
    "NameScope: " + e.NameScope + Environment.NewLine +
    "ReceiverName: " + e.ReceiverName + Environment.NewLine +
    "SenderDomain: " + e.SenderDomain + Environment.NewLine +
    "Response: " + e.Response;
}


strana 420
----------
<Grid x:Name="LayoutRoot" Background="White">
  <ListBox Name="listBox1" Height="150" Width="200" 
    HorizontalAlignment="Left" VerticalAlignment="Top"/>

</Grid>
C#:
public partial class MainPage : UserControl
{
  public MainPage()
  {
    InitializeComponent();
    listBox1.ItemsSource = Kontakty.Kontakt;
    listBox1.DisplayMemberPath = "jmeno";

  }
}

public class Kontakty
{
  public String jmeno { get; set; }
  public String mesto { get; set; }

  public Kontakty(String Jmeno, String Mesto)
  {
    jmeno = Jmeno;
    mesto = Mesto;
  }

  public static List<Kontakty> kontakt = new List<Kontakty>();

  public static List<Kontakty> Kontakt
  {
    get
    {
      for (int i = 0; i < 100; i++)
      {
        kontakt.Add(new Kontakty("Novk" + i.ToString(), "Nae msto" + 
          i.ToString()));
      }
      return kontakt;
    }
  }
}





strana 421
----------
<Grid x:Name="LayoutRoot" Background="White">
  <Ellipse 
    Height="100" Width="100" Name="kruh"
    HorizontalAlignment="Left" VerticalAlignment="Top"
    Stroke="Black" StrokeThickness="3" Fill="Blue" />

</Grid>


C#:
public MainPage()
{
  InitializeComponent();
  kruh.MouseWheel += new MouseWheelEventHandler(kruh_MouseWheel);
}

void kruh_MouseWheel(object sender, MouseWheelEventArgs e)
{
  double dH = kruh.Height;
  double dW = kruh.Width;

  int delta = e.Delta;

  dH += delta;
  dW += delta;

  kruh.Height = dH < 25 ? 25 : dH;
  kruh.Width = dW < 25 ? 25 : dW;
}


strana 425
----------
<HyperlinkButton x:Name="Link3" Style="{StaticResource LinkStyle}" 
  NavigateUri="/Page1" TargetName="ContentFrame" Content="Moje strnka"/>



strana 435
----------
C#:
public IQueryable<Product> GetSortedProduct()
{
  return this.ObjectContext.Product.OrderBy(e => e.ProductNumber);
}

public IQueryable<Product> GetRedProduct()
{
  return this.ObjectContext.Product.Where(e => e.Color == "Red");
}



strana 436
----------
<HyperlinkButton x:Name="Link3" Style="{StaticResource LinkStyle}" 
  NavigateUri="/Produkty" 
  TargetName="ContentFrame" Content="{Binding 
  Path=ApplicationStrings.ProduktyPageTitle, 
  Source={StaticResource ResourceWrapper}}"/>

<Rectangle x:Name="Divider3" Style="{StaticResource DividerStyle}"/>




strana 437
----------
C#:
public Produkty()
{
  InitializeComponent();
  Loaded += new RoutedEventHandler(Produkty_Loaded);
}

void Produkty_Loaded(object sender, RoutedEventArgs e)
{
  AwDomainContext ctx = new AwDomainContext();
  dataGrid1.ItemsSource = ctx.Products;
  ctx.Load(ctx.GetProductQuery());
}




strana 443
----------
<dataform:DataForm x:Name="dataForm1" Header="Informace o produktu" 
  AutoGenerateFields="False" AutoEdit="False" AutoCommit="False" 
  CurrentItem="{Binding SelectedItem, ElementName=dataGrid1}" 
  Margin="0,12,0,0">
  <dataform:DataForm.EditTemplate>
    <DataTemplate>
      <StackPanel>
        <dataform:DataField Label="ProductID">
          <TextBox IsReadOnly="True" 
            Text="{Binding ProductID, Mode=OneWay}" />
        </dataform:DataField>
        <dataform:DataField Label="Name">
          <TextBox Text="{Binding Name, Mode=TwoWay}" />
        </dataform:DataField>
        <dataform:DataField Label="ProductNumber">
          <TextBox Text="{Binding ProductNumber, Mode=TwoWay}" />
        </dataform:DataField>
        <dataform:DataField Label="ProductModelID">
          <TextBox Text="{Binding ProductModelID, Mode=TwoWay}" />
        </dataform:DataField>
        <dataform:DataField Label="Color">
          <TextBox Text="{Binding Color, Mode=TwoWay}" />
        </dataform:DataField>
        <dataform:DataField Label="StandardCost">
          <TextBox Text="{Binding StandardCost, Mode=TwoWay,
            NotifyOnValidationError=True,  
            ValidatesOnExceptions=True }"  />
        </dataform:DataField>
        <dataform:DataField Label="ListPrice">
          <TextBox Text="{Binding ListPrice, Mode=TwoWay, 
            NotifyOnValidationError=True,  
            ValidatesOnExceptions=True }"  />
        </dataform:DataField>
        <dataform:DataField Label="Size">
          <TextBox Text="{Binding Size, Mode=TwoWay, 
            NotifyOnValidationError=True,  
            ValidatesOnExceptions=True }"  />
        </dataform:DataField>
        <dataform:DataField Label="Weight">
          <TextBox Text="{Binding Weight, Mode=TwoWay, 
            NotifyOnValidationError=True,  
            ValidatesOnExceptions=True }"  />
        </dataform:DataField>
      </StackPanel>
    </DataTemplate>
  </dataform:DataForm.EditTemplate>
</dataform:DataForm>



strana 410
----------
